package cn.littlehx.myweb.api;

import cn.littlehx.myweb.common.R;
import cn.littlehx.myweb.domain.User;
import cn.littlehx.myweb.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 进行后台的用户管理
 */
@RestController
@RequestMapping("/backend/user")
public class UserApiController {
    @Autowired
    private IUserService userService;
    @DeleteMapping()
    public R delete(@RequestBody User user){
        User userGot = userService.selectByEmailAndPassword(user.getEmail(), user.getPassword());
        if(userGot == null){
            return new R(false,null,"未找到当前用户,请确认邮箱和密码");
        }
        boolean flag = userService.removeById(userGot.getId());
        if(flag){
            return new R(true,null,"删除成功");
        }else {
            return new R(false,null,"服务器出错,请稍后重试");
        }
    }

}
